package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysProjectProductRel;
import com.ruoyi.system.service.ISysProjectProductRelService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目产品关系Controller
 * 
 * @author ruoyi
 * @date 2020-12-28
 */
@Controller
@RequestMapping("/system/rel")
public class SysProjectProductRelController extends BaseController
{
    private String prefix = "system/rel";

    @Autowired
    private ISysProjectProductRelService sysProjectProductRelService;

    @RequiresPermissions("system:rel:view")
    @GetMapping()
    public String rel()
    {
        return prefix + "/rel";
    }

    /**
     * 查询项目产品关系列表
     */
    @RequiresPermissions("system:rel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysProjectProductRel sysProjectProductRel)
    {
        startPage();
        List<SysProjectProductRel> list = sysProjectProductRelService.selectSysProjectProductRelList(sysProjectProductRel);
        return getDataTable(list);
    }

    /**
     * 导出项目产品关系列表
     */
    @RequiresPermissions("system:rel:export")
    @Log(title = "项目产品关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysProjectProductRel sysProjectProductRel)
    {
        List<SysProjectProductRel> list = sysProjectProductRelService.selectSysProjectProductRelList(sysProjectProductRel);
        ExcelUtil<SysProjectProductRel> util = new ExcelUtil<SysProjectProductRel>(SysProjectProductRel.class);
        return util.exportExcel(list, "rel");
    }

    /**
     * 新增项目产品关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目产品关系
     */
    @RequiresPermissions("system:rel:add")
    @Log(title = "项目产品关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysProjectProductRel sysProjectProductRel)
    {
        return toAjax(sysProjectProductRelService.insertSysProjectProductRel(sysProjectProductRel));
    }

    /**
     * 修改项目产品关系
     */
    @GetMapping("/edit/{relId}")
    public String edit(@PathVariable("relId") Long relId, ModelMap mmap)
    {
        SysProjectProductRel sysProjectProductRel = sysProjectProductRelService.selectSysProjectProductRelById(relId);
        mmap.put("sysProjectProductRel", sysProjectProductRel);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目产品关系
     */
    @RequiresPermissions("system:rel:edit")
    @Log(title = "项目产品关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysProjectProductRel sysProjectProductRel)
    {
        return toAjax(sysProjectProductRelService.updateSysProjectProductRel(sysProjectProductRel));
    }

    /**
     * 删除项目产品关系
     */
    @RequiresPermissions("system:rel:remove")
    @Log(title = "项目产品关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysProjectProductRelService.deleteSysProjectProductRelByIds(ids));
    }
}
